package bbstorespringmvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import bbstorespringmvc.model.Book;
import bbstorespringmvc.repository.BookRepository;
@Controller
public class BookDisplayController {
	@Autowired BookRepository bookRepository;
	@RequestMapping("displaydetails")
	public ModelAndView displayBook(@RequestParam("id") Long id){
		Book book= (Book) bookRepository.findById(id);
		if (book==null) return new ModelAndView("error", "id", id);
		ModelAndView mv = new ModelAndView("bookdisplay","book",book);
		return mv;
	}
}
